﻿
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_AddFile]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_AddFile];
GO
CREATE PROCEDURE [dbo].[sproc_AddFile]
    @DocID int=0,
    @FileName nvarchar(255),
    @FileSize int,
    @FileAttribute int,
    @FileVisualPath nvarchar(255),
    @FileAuthor nvarchar(255),
    @FileCatlog nvarchar(255),
    @FileAddedDate datetime,
    @Fininshed int =0
/*
===================================================

功能:    添加文档的关联文件记录
参数:
    @DocID         被关联文档的ID
    @FileName         文件名
    @FileSize         文件大小
    @FileAttribute         文件属性(暂未使用)
    @FileVisualPath     文件所在虚拟路径
    @FileAuthor         文件的作者
    @FileCatlog         文件所在分类
    @FileAddedDate     文件添加的日期
    @Fininshed int =0    是否完成对文档的关联标记

===================================================
*/
AS

IF @DocID <>0 
    INSERT INTO uds_files (DOCID,[FILENAME],FILESIZE,FILEATTRIBUTE, FILEVISUALPATH,FILEAUTHOR,FILECATLOG,FILEADDEDDATE)
        VALUES(@DocID,@FileName,@FileSize,@FileAttribute,@FileVisualPath,@FileAuthor,@FileCatlog,@FileAddedDate)
ELSE
    INSERT INTO uds_files (DOCID,[FILENAME],FILESIZE,FILEATTRIBUTE, FILEVISUALPATH,FILEAUTHOR,FILECATLOG,FILEADDEDDATE)
        SELECT DocID,@FileName,@FileSize,@FileAttribute,@FileVisualPath,@FileAuthor,@FileCatlog,@FileAddedDate 
            FROM uds_document 
            WHERE docsign = @@SPID and DocAttribute >0

IF @fininshed >0 
    UPDATE uds_document 
        SET docattribute =0 ,docsign =0 
        WHERE docsign = @@spid and DocAttribute >0